package io.renren.modules.bike.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.bike.dao.BikeDao;
import io.renren.modules.bike.entity.BikeEntity;
import io.renren.modules.bike.service.BikeService;


@Service("bikeService")
public class BikeServiceImpl extends ServiceImpl<BikeDao, BikeEntity> implements BikeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        IPage<BikeEntity> page = null;
        if (key != null) {
            page = this.page(
                    new Query<BikeEntity>().getPage(params),
                    new QueryWrapper<BikeEntity>().like("b_name", key)
                            .or().like("b_state", key).or().like("b_comment", key)
            );
        } else {
            page = this.page(
                    new Query<BikeEntity>().getPage(params),
                    new QueryWrapper<BikeEntity>()
            );
        }

        return new PageUtils(page);
    }

    @Autowired
    BikeDao bikeDao;

    @Override
    public void updateByOBid(Integer oBid) {
        bikeDao.updateByOBid(oBid);
    }

    @Override
    public PageUtils queryPageWeiXiu(Map<String, Object> params) {
        IPage<BikeEntity> page = this.page(
                new Query<BikeEntity>().getPage(params),
                new QueryWrapper<BikeEntity>().like("b_state", "维修").or().like("b_state", "报废")
        );

        return new PageUtils(page);
    }

}
